package cn.sunline.dreamvalue.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author 11292
 * @title: SubTableUtil
 * @projectName dream-value
 * @description: 分表后缀获取工具类
 * @date 2020/5/722:55
 */
@Component
public class SubTableUtil {

    @Value("${cn.sunline.subtablecount}")
    private Integer subTableCount;

    public Integer getTableSuffix(String dreamValueNo){
        //分表策略为，计算出dreamValueNo的hash值，再对分表数量取余得到的结果为分表后缀
        return (Math.floorMod(dreamValueNo.hashCode(),subTableCount)) + 1;
    }

}
